<?php
/**
 * 角色与菜单关联模型
 */

namespace app\model\admin\run;

use laytp\BaseModel;
use think\Exception;

class Proplevel extends BaseModel
{
    protected $name = 'run_prop_level';


    /**
     * 道具升级初始化
     * @param $prop_id
     * @param $game_id
     * @param $min_level
     * @param $max_level
     * @return bool
     */
    public function initPropLevel($prop_id,$game_id,$min_level,$max_level){
        try {
            if(empty($prop_id) || empty($min_level) || empty($max_level)){
                throw new Exception("参数不正确");
            }

            if($max_level <= $min_level){
                throw new Exception("等级格式不正确");
            }

            $insData = [];
            foreach(range($min_level,$max_level) as $level){
                $insData[] = array(
                    'game_id' => $game_id,
                    'prop_id' => $prop_id,
                    'level' => $level,
                    'material_id' => 0,
                    'material_num' => 0
                );
            }

            $count= $this->insertAll($insData);
            if($count <= 0){
                throw new Exception("初始失败");
            }
            return true;
        }catch (\Exception $e){
            return false;
        }
    }
}